package cn.com.dhc.danlu.widget.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import cn.com.dhc.danlu.R;

public class OrderCouponAdapter extends BaseAdapter {

    private Context context;
    private int selectedIndex = 0;

    public OrderCouponAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        CouponViewHolder holder;
        if (arg1 == null) {
            holder = new CouponViewHolder();
            arg1 = LayoutInflater.from(context).inflate(R.layout.layout_order_coupon_item, null);
            holder.couponImg = (ImageView) arg1.findViewById(R.id.couponImg);
            arg1.setTag(holder);
        } else {
            holder = (CouponViewHolder) arg1.getTag();
        }
        holder.couponImg.setImageResource(R.drawable.ic_not_check);
        if (selectedIndex == arg0) {
            // 选中
            holder.couponImg.setImageResource(R.drawable.ic_check);
        } else {
            // 未选中
            holder.couponImg.setImageResource(R.drawable.ic_not_check);
        }
        return arg1;
    }

    public void setSelectedIndex(int index) {
        this.selectedIndex = index;
    }

    private static class CouponViewHolder {
        private ImageView couponImg;
    }
}